<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
<head>
  <link href="//gmpg.org/xfn/11" rel="profile">
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta name="generator" content="Hugo 0.69.0" />

  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title>md5加密方法 &middot; 郝朝帅的博客</title>

  
  <link type="text/css" rel="stylesheet" href="/blog/css/print.css" media="print">
  <link type="text/css" rel="stylesheet" href="/blog/css/poole.css">
  <link type="text/css" rel="stylesheet" href="/blog/css/syntax.css">
  <link type="text/css" rel="stylesheet" href="/blog/css/hyde.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Abril+Fatface|PT+Sans:400,400i,700">


  
  <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-144-precomposed.png">
  <link rel="shortcut icon" href="/favicon.png">

  
  
</head>

  <body class="theme-base-0f ">
  <aside class="sidebar">
  <div class="container sidebar-sticky">
    <div class="sidebar-about">
      <a href="/blog/"><h1>郝朝帅的博客</h1></a>
      <p class="lead">
       我的个人博客 
      </p>
    </div>

    <nav>
      <ul class="sidebar-nav">
        <li><a href="/blog/">Home</a> </li>
        
      </ul>
    </nav>

    <p>&copy; 2020. All rights reserved. </p>
  </div>
</aside>

    <main class="content container">
    <div class="post">
  <h1>md5加密方法</h1>
  <time datetime=2020-04-24T20:05:06&#43;0800 class="post-date">Fri, Apr 24, 2020</time>
  <p>##md5加密方法</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#75715e">#导入加密库</span>
<span style="color:#f92672">import</span> hashlib

<span style="color:#75715e">#md5加密方法</span>
<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">make_password</span>(mypass):
    <span style="color:#75715e">#生成md5对象</span>
    md5 <span style="color:#f92672">=</span> hashlib<span style="color:#f92672">.</span>md5()
    <span style="color:#75715e">#定义加密对象</span>
    sign_str <span style="color:#f92672">=</span> mypass
    <span style="color:#75715e">#转码</span>
    sign_utf8 <span style="color:#f92672">=</span> str(sign_str)<span style="color:#f92672">.</span>encode(encoding<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;utf-8&#34;</span>)
    <span style="color:#75715e">#加密操作</span>
    md5<span style="color:#f92672">.</span>update(sign_utf8)
    <span style="color:#75715e">#生成密文</span>
    md5_server <span style="color:#f92672">=</span> md5<span style="color:#f92672">.</span>hexdigest()
    <span style="color:#66d9ef">return</span> md5_server

</code></pre></div>
</div>


    </main>

    
  </body>
</html>
